<template>
    <div class="sign-up-info">
        <div class="search-content">
            <div class="time-range-wrapper">
                <span class="time-range-label">下单时间：</span>
                <el-date-picker
                    v-model="addTime"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                ></el-date-picker>
            </div>
            <div class="time-range-wrapper">
                <span class="span-title">支付时间：</span>
                <el-date-picker
                    v-model="payTime"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                ></el-date-picker>
            </div>
            <span class="span-title">会员姓名：</span>
            <el-input
                class="search-content-input"
                v-model="searchContent.member_name"
                placeholder="会员姓名"
            ></el-input>
            <span class="span-title">会员手机号：</span>
            <el-input
                class="search-content-input"
                v-model="searchContent.member_mobile"
                placeholder="会员手机号"
            ></el-input>
            <span class="span-title">店铺名称：</span>
            <el-input
                class="search-content-input"
                v-model="searchContent.store_name"
                placeholder="店铺名称"
            ></el-input>
            <span class="span-title">订单状态：</span>
            <el-select v-model="searchContent.pay_status" placeholder="订单状态">
                <el-option
                    v-for="item in statusList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                ></el-option>
            </el-select>
            <span class="span-title">支付渠道：</span>
            <el-select v-model="searchContent.pay_channel" placeholder="支付渠道">
                <el-option
                    v-for="item in channelList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                ></el-option>
            </el-select>
            <span class="span-title">订单号：</span>
            <el-input
                class="search-content-input"
                v-model="searchContent.pay_ordersn"
                placeholder="订单号"
            ></el-input>
            <span class="span-title">有效性：</span>
            <el-select v-model="searchContent.enabled" placeholder="有效性">
                <el-option
                    v-for="item in enabledList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                ></el-option>
            </el-select>
            <span class="span-title">支付分类：</span>
            <el-select v-model="searchContent.channels" placeholder="支付分类">
                <el-option
                    v-for="item in channelsList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                ></el-option>
            </el-select>
            <span class="span-title">订单来源：</span>
            <el-select v-model="searchContent.source" placeholder="订单来源">
                <el-option
                    v-for="item in sourceList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                ></el-option>
            </el-select>
            <!-- <span class="span-title">红包主题：</span>
            <el-input
                class="search-content-input"
                v-model="searchContent.car_theme_name"
                placeholder="红包主题"
            ></el-input> -->
            <span class="span-title">复核状态：</span>
            <el-select clearable v-model="searchContent.review_status" placeholder="复核状态">
                <el-option value="points_yes" label="积分已复核"></el-option>
                <el-option value="points_no" label="积分未复核"></el-option>
                <el-option value="hb_yes" label="红包已复核"></el-option>
                <el-option value="hb_no" label="红包未复核"></el-option>
            </el-select>
			<el-checkbox v-model="searchContent.hb_money" :true-label="1" :false-label="0">红包抵扣</el-checkbox>
			<el-checkbox v-model="searchContent.pay_points" :true-label="1" :false-label="0">积分抵扣</el-checkbox>
            <el-button class="seachBtn" type="primary" @click="search">搜索</el-button>
            <el-button type="primary" @click="resetSearchData">重置</el-button>
        </div>
        <div class="search-list">
            <el-table
                :data="couponList"
                border
                :height="oHeight"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column align="center" prop="pay_id" label="编号" min-width="60"></el-table-column>
                <el-table-column align="center" prop="pay_ordersn" label="订单号" min-width="160"></el-table-column>
                <el-table-column align="center" prop="store_name" label="店铺" min-width="120"></el-table-column>
                <el-table-column align="center" prop="member_name" label="用户账号" min-width="120"></el-table-column>
                <el-table-column align="center" label="手机号	" prop="member_mobile" min-width="120"></el-table-column>
                <el-table-column align="center" prop="pay_want_money" label="消费金额	" min-width="90"></el-table-column>
                <el-table-column align="center" prop="discount_money" label="优惠金额	" min-width="90"></el-table-column>
                <el-table-column prop="pay_points" align="center" label="积分抵扣	" min-width="120"></el-table-column>
                <el-table-column align="center" prop="hb_money" label="红包抵扣	" min-width="90"></el-table-column>
                 <el-table-column prop="points_review_desc" align="center" label="积分复核	" min-width="120"></el-table-column>
                <el-table-column align="center" prop="hb_review_desc" label="红包复核	" min-width="90"></el-table-column>
                <el-table-column align="center" prop="other_money" label="其他金额	" min-width="90"></el-table-column>
                <el-table-column align="center" prop="pay_money" label="实际付款	" min-width="90"></el-table-column>
                <el-table-column align="center" label="时间" prop="add_time" min-width="90"></el-table-column>
                <el-table-column align="center" prop="note" label="备注信息	" min-width="90"></el-table-column>
                <el-table-column align="center" prop="channels_desc" label="支付分类	" min-width="90"></el-table-column>
                <el-table-column align="center" label="订单状态" prop="pay_status_desc" min-width="90"></el-table-column>
                <el-table-column align="center" prop="bytc_desc" label="保养套餐状态	" min-width="100"></el-table-column>
                <el-table-column align="center" prop="source_desc" label="来源	" min-width="90"></el-table-column>
                <el-table-column align="center" prop="enabled_desc" label="是否有效	" min-width="90"></el-table-column>
				<el-table-column align="center" prop="is_bill_desc" label="对账状态" min-width="80"></el-table-column>
				<el-table-column align="center" prop="is_review_desc" label="复核状态" min-width="80"></el-table-column>
                <el-table-column
                    fixed="right"
                    align="center"
                    label="操作"
                    min-width="350"
                    #default="{ row }"
                >
                    <!-- <el-button @click="refund(scope.row.id)" type="primary" size="mini">退款</el-button> -->
					<!-- <el-button
                        v-if="row.is_review!=='1'"
                        type="primary"
                        @click="review(row)"
                    >复核</el-button> -->
                    <el-button
                        v-if="row.points_reconciliation_status==='1' && row.points_review_status==='0'&& row.pay_points && Number(row.pay_points)>1"
                        type="primary"
                        @click="JFreview(row)"
                    >积分复核</el-button>
                   
                    <el-button
                        v-if="row.hb_reconciliation_status ==='1' &&row.hb_review_status==='0'&& row.hb_money && Number(row.hb_money)>1"
                        type="primary"
                        @click="HBreview(row)"
                    >红包复核</el-button>
                  
					<el-button
                        v-if="row.can_rollback===true"
                        type="primary"
                        @click="billRollback(row)"
                    >对账退回</el-button>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group">
                    <a class="btn-bottom" style="cursor:pointer" @click="exportLink">导出</a>
                    <a class="btn-bottom" style="cursor:pointer;margin-left:10px;" @click="oneReviewHB">一键红包复核</a>
                    <a class="btn-bottom" style="cursor:pointer;margin-left:10px;" @click="oneReviewJF">一键积分复核</a>
                  
                </div>
                <div class="paginationOne">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="searchContent.page"
                        :page-sizes="[10, 20, 50, 100]"
                        :page-size="searchContent.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total"
                    ></el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { resize } from "@/common/js/height.js";
import Qs from 'qs'
import { dateFormatter } from "../../../../common/js/util";
export default {
    data() {
        return {
            couponList: [],
            statusList: [],//订单状态
            channelsList: [],//支付分类
            enabledList: [],//有效无效
            channelList: [],//支付渠道
            sourceList: [],//订单来源
            oHeight: 800,
            addTime: '',
            payTime: '',
            searchContent: {
                add_time_start: '',
                add_time_end: '',
                pay_time_start: '',
                pay_time_end: '',
                project_class: '',
                member_name: '',
                member_mobile: '',
                store_name: '',
                pay_status: '',
                pay_channel: '',
                pay_ordersn: '',
                enabled: '',
                channels: '',
                source: '',
                car_theme_name: '',
                page: 1,
                pageSize: localStorage.getItem('pageSize') * 1 || 10,
                form_submit: '',
                is_bill: '',
				is_review:'',
				pay_points:"",
                review_status:"",
                points_review_desc:"",
                is_review_page:1,
                hb_review_desc:""

            },
            total: 0,
            check: []
        }
    },
    created() {
        this.getListData();
        this.getstatus();
        this.getchannels();
        this.getenabled();
        this.getchannel();
        this.getsource();
    },
    computed: {
    },
    methods: {

handleSelectionChange(val){
    this.check = val;
},
 oneReviewHB(type) {
   let url = '/admin/bill/index.php?act=onlineBill&op=onlineOrderReview';
      let idArr = [];
      let dataErr = false;
      if (this.check.length === 0) {
        this.$message.warning("请勾选数据");
        return;
      }
      this.check.forEach((item) => {
          if(item.hb_reconciliation_status ==="1" && item.hb_money && Number(item.hb_money)>1){
               
               idArr.push(item.pay_id);

          }else{

                 dataErr = true;

          }
        
      
      });
      if (dataErr) {
        this.$message.error("请选择正确的状态！");
        return;
      }
      this.$confirm("确认").then((res) => {
      this.$http
        .post(url, {
        pay_id:idArr,
        review_type:'hb'
        })
        .then((res) => {
          if (res.code === 1) {
            this.$message.success(res.msg);
            this.search();
             this.getListData();
          } else {
            this.$message.warning(res.msg);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
          });
    },

oneReviewJF(type) {
   let url = '/admin/bill/index.php?act=onlineBill&op=onlineOrderReview';
      let idArr = [];
      let dataErr = false;
      if (this.check.length === 0) {
        this.$message.warning("请勾选数据");
        return;
      }
      this.check.forEach((item) => {
        
       if(item.points_reconciliation_status==="1" && item.pay_points && Number(item.pay_points)>1){
               
               idArr.push(item.pay_id);

          }else{

          
          dataErr = true;
        }

          
      
      });
      if (dataErr) {
        this.$message.error("请选择正确的状态！");
        return;
      }
      this.$confirm("确认").then((res) => {
      this.$http
        .post(url, {
        pay_id:idArr,
        review_type:'points'
        })
        .then((res) => {
          if (res.code === 1) {
            this.$message.success(res.msg);
            this.search();
             this.getListData();
          } else {
            this.$message.warning(res.msg);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
          });
    },

        //单个红包复核
      HBreview(row) {
        this.$confirm("确认").then((res) => {   
      this.$http
        .post("/admin/bill/index.php?act=onlineBill&op=OnlineOrderReview", {
          pay_id: row.pay_id,
          review_type: "hb",
        })
        .then((res) => {
          if (res.code === 1) {
            this.$message.success(res.msg);
            this.getListData();
            
          } else {
            this.$message.warning(res.msg);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
        });
    },
   
    //单个积分复核
      JFreview(row) {
       this.$confirm("确认").then((res) => {       
      this.$http
        .post("/admin/bill/index.php?act=onlineBill&op=OnlineOrderReview", {
          pay_id: row.pay_id,
          review_type: "points",
        })
        .then((res) => {
          if (res.code === 1) {
            this.$message.success(res.msg);
             this.getListData();
          } else {
            this.$message.warning(res.msg);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
        });
    },

   
    



        //订单状态获取
        getstatus() {
            this.$http.post('/admin/onlinePay/index.php?act=order&op=getPayStatus').then(res => {
                if (res.code == 1) {
                    this.statusList = res.data;
                }
            })
        },
        //支付渠道获取
        getchannels() {
            this.$http.post('/admin/onlinePay/index.php?act=order&op=getPayChannels').then(res => {
                if (res.code == 1) {
                    this.channelsList = res.data;
                }
            })
        },
        //有效无效获取
        getenabled() {
            this.$http.post('/admin/onlinePay/index.php?act=order&op=getEnabled').then(res => {
                if (res.code == 1) {
                    this.enabledList = res.data;
                }
            })
        },
        //支付分类获取
        getchannel() {
            this.$http.post('/admin/bill/index.php?act=reconciliation&op=getBusinessTypes').then(res => {
                if (res.code == 1) {
                    this.channelList = res.data;
                }
            })
        },
        //订单来源获取
        getsource() {
            this.$http.post('/admin/onlinePay/index.php?act=order&op=getPaySources').then(res => {
                if (res.code == 1) {
                    this.sourceList = res.data;
                }
            })
        },
        search() {
            this.searchContent.page = 1;
            this.getListData();
        },
        resetSearchData() {
            this.addTime = '';
            this.payTime = '';
            this.searchContent = {
                page: 1,
                pageSize: localStorage.getItem('pageSize') * 1 || 10,
				pay_points:0,
				hb_money:0
            }
            this.getListData();
        },
        handleSizeChange(pageSize) {
            this.searchContent.pageSize = pageSize;
            this.searchContent.page = 1;
            this.getListData();
        },
        handleCurrentChange(page) {
            this.searchContent.page = page;
            this.getListData();
        },
        getListData() {
            const data = this.searchContent;
            //已对账订单
			data.is_bill = '1';
            data.is_export = '';
            data.exportLink="1";
            data.is_review_page=1;
          
                             
            if (this.addTime) {
                const startAddMS = this.addTime[0].getTime();
                const endAddMS = this.addTime[1].getTime();
                if (startAddMS == endAddMS) {
                    data.add_time_start = dateFormatter('YYYY-MM-DD ', startAddMS);
                    data.add_time_end = dateFormatter('YYYY-MM-DD ', endAddMS + (24 * 60 * 60 - 1) * 1000);
                } else {
                    data.add_time_start = dateFormatter('YYYY-MM-DD ', this.addTime[0]);
                    data.add_time_end = dateFormatter('YYYY-MM-DD ',  endAddMS + (24 * 60 * 60 - 1) * 1000);
                }
            }
            if (this.payTime) {
                const startPAYMS = this.payTime[0].getTime();
                const endPAYMS = this.payTime[1].getTime();
                if (startPAYMS == endPAYMS) {
                    data.pay_time_start = dateFormatter('YYYY-MM-DD ', startPAYMS);
                    data.pay_time_end = dateFormatter('YYYY-MM-DD ', endPAYMS + (24 * 60 * 60 - 1) * 1000);
                } else {
                    data.pay_time_start = dateFormatter('YYYY-MM-DD ', this.payTime[0]);
                    data.pay_time_end = dateFormatter('YYYY-MM-DD ', endPAYMS + (24 * 60 * 60 - 1) * 1000);
                }
            }
            this.$http.post('/admin/onlinePay/index.php?act=order&op=payedList', data).then(res => {
                if (res.code == 1) {
                    if (res.data && res.data.list) {
                        this.couponList = res.data.list.map(function (item) {
                            return {
                                pay_id: item.pay_id,
                                pay_ordersn: item.pay_ordersn,
                                add_time: item.add_time,
                                pay_want_money: item.pay_want_money,
                                pay_money: item.pay_money,
                                pay_points: item.pay_points,
                                hb_money: item.hb_money,
                                note: item.note,
                                other_money: item.other_money,
								pay_status:item.pay_status,
                                pay_status_desc: item.pay_status_desc,
                                pay_channel_desc: item.pay_channel_desc,
                                channels_desc: item.channels_desc,
                                enabled_desc: item.enabled_desc,
                                store_name: item.store_name,
                                member_name: item.member_name,
                                member_mobile: item.member_mobile,
                                bytc_desc: item.bytc_desc,
                                is_bill: item.is_bill,
								is_review: item.is_review,
                                is_bill_desc: item.is_bill_desc,
                                is_review_desc: item.is_review_desc,
                                points_review_desc:item.points_review_desc,
                                hb_review_desc:item.hb_review_desc,
                                can_rollback:item.can_rollback,
                                points_review_status:item.points_review_status,
                                hb_review_status:item.hb_review_status,
                                points_reconciliation_status:item.points_reconciliation_status,
                                hb_reconciliation_status:item.hb_reconciliation_status


                            }
                        });
                        this.total = parseInt(res.data.totalCount);
                        this.channelList = res.data.class_list;
                    } else {
                        this.couponList = [];
                        this.total = 0;
                    }
                } else if (res.code == 2001) {
                    this.couponList = [];
                    this.total = 0;
                } else {
                    alert(res.msg);
                }
            })
        },
        dateFormat(row) {
            console.log('888888', row);
            var timestamp = row;
            var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
            console.log('1111', timestamp);
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var D = date.getDate() + ' ';
            return Y + M + D;
        },
        exportLink() {
            const data = this.searchContent;
            data.is_export = 1;
            if (this.addTime) {
                const startAddMS = this.addTime[0].getTime();
                const endAddMS = this.addTime[1].getTime();
                if (startAddMS == endAddMS) {
                    data.add_time_start = dateFormatter('YYYY-MM-DD ', startAddMS);
                    data.add_time_end = dateFormatter('YYYY-MM-DD ', endAddMS + (24 * 60 * 60 - 1) * 1000);
                } else {
                    data.add_time_start = dateFormatter('YYYY-MM-DD ', this.addTime[0]);
                    data.add_time_end = dateFormatter('YYYY-MM-DD ', this.addTime[1]);
                }
            }
            if (this.payTime) {
                const startPAYMS = this.payTime[0].getTime();
                const endPAYMS = this.payTime[1].getTime();
                if (startPAYMS == endPAYMS) {
                    data.pay_time_start = dateFormatter('YYYY-MM-DD ', startAddMS);
                    data.pay_time_end = dateFormatter('YYYY-MM-DD ', endAddMS + (24 * 60 * 60 - 1) * 1000);
                } else {
                    data.pay_time_start = dateFormatter('YYYY-MM-DD ', this.payTime[0]);
                    data.pay_time_end = dateFormatter('YYYY-MM-DD ', this.payTime[1]);
                }
            }
            let domain = document.domain;
            var url = location.protocol + '//' + domain.replace('admin', 'api') + '/admin/onlinePay/index.php?act=order&op=payedList';
            console.log(url);
            for (var key in data) {
                if (
                    !(
                        data[key] === null ||
                        data[key] === "" ||
                        data[key] === undefined
                    )
                ) {
                    url += "&" + key + "=" + data[key];
                }
            }
            console.log(url);
            window.location.href = url;
        },
        review(row) {
			console.log(row)
            this.$http.post('/admin/bill/index.php?act=onlineBill&op=review', {
                id:row.pay_id,
				order_type:'2'
            }).then((res) => {
                if (res.code === 1) {
					row.is_review='1';
					row.is_review_desc='已复核';
                    this.$message.success(res.msg);
                } else {
                    this.$message.warning(res.msg);
                }
            }).catch(err => {
                this.$message.error( err);
            })
        },
        billRollback(row) {
            this.$http.post('/admin/bill/index.php?act=onlineBill&op=onlineOrderReconciliationRollback', {
                pay_id:row.pay_id
               
            }).then((res) => {
               
                    this.$message.success(res.msg);
              
            }).catch(err => {
                this.$message.error(err);
            })
        }
    },
    mounted() {
        resize(this)
    },
}
</script>

<style lang="scss" scoped>
.seachBtn{
	margin-left:10px;
}
.sign-up-info {
    .search-content {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        &-input {
            width: 200px;
        }
        .time-range-wrapper {
            .time-range-label {
                font-size: 14px;
            }
            display: flex;
            align-items: center;
            /deep/.el-range-separator {
                box-sizing: content-box;
            }
        }
    }
    .bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}
.btn-bottom {
    background: #409eff;
    color: #fff;
    border: 0;
    font-size: 14px;
    padding: 5px 8px;
    border-radius: 3px;
    display: inline-block;
}
.span-title {
    font-size: 14px;
    color: rgb(46, 45, 45);
}
</style>